import { BaseWindow } from "../../../../component/window/BaseWindow";
import { PageTool } from "../../../../common/global/PageTool";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GComboBox } from "../../../../../com/mui/controls/GComboBox";
import { ListMenuCellRenderer } from "../../common/menu/ListMenuCellRenderer";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { TilePanel } from "../../equipment/TilePanel";
import { RecordRenderer } from "./RecordRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { Cache } from "../../../cache/Cache";
//class RecordListWindow
    
    export  class RecordListWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 5);
            this.init();
            this.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            return;
        }

        public init(): void
        {
            this.setSize(500, 282);
            this.titleHeight = 28;
            ObjCreate.createBg(17, 40, 466, 230, this);
            this.title = Language.getString(57261);
            var loc1=45;
            ObjCreate.createTextField(Language.getString(57262), 30, loc1, 170, 20, this);
            ObjCreate.createTextField(Language.getString(57263), 95, loc1, 170, 20, this);
            ObjCreate.createTextField(Language.getString(27983), 190, loc1, 170, 20, this);
            ObjCreate.createTextField(Language.getString(57264), 305, loc1, 170, 20, this);
            ObjCreate.createTextField(Language.getString(57265), 370, loc1, 170, 20, this);
            this._operCombo = new GComboBox();
            this._operCombo.move(415, loc1);
            this._operCombo.width = 60;
            this._operCombo.height = 20;
            this._operCombo.buttonMode = true;
            this._operCombo.styleName = "GComboboxStyle";
            this._operCombo.drawNow();
            this._operCombo.dropdown.setStyle("cellRenderer", ListMenuCellRenderer);
            this._operCombo.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._operCombo.textField.setStyle("textFormat", new GTextFormat("", 12, 11661308, false, false, false, "", "", flash.text.TextFormatAlign.CENTER));
            this._operDp = new DataProvider();
            this._operDp.addItem({"id": 0, "label": Language.getString(57266)});
            this._operDp.addItem({"id": 1, "label": Language.getString(57267)});
            this._operDp.addItem({"id": 2, "label": Language.getString(57268)});
            this._operDp.addItem({"id": 3, "label": Language.getString(57636)});
            this._operCombo.dataProvider = this._operDp;
            this._operCombo.selectedIndex = 0;
            this._operCombo.addEventListener(flash.events.Event.CHANGE, this.onCampComboBoxChangeHandler);
            addChild(this._operCombo);
            ObjCreate.createBg(22, 70, 460, 2, this, ImagesConst.SplitLine);
            this._itemListPanel = new TilePanel();
            this._itemListPanel.horizontalGap = 3;
            this._itemListPanel.verticalGap = 2;
            this._itemListPanel.setSize(460, 160);
            this._itemListPanel.columnWidth = 460;
            this._itemListPanel.rowHeight = 30;
            this._itemListPanel.setStyle("cellRenderer", RecordRenderer);
            this._itemListPanel.move(11, 70);
            this.addChild(this._itemListPanel);
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.SingleMode;
            this._pageBar.x = 180;
            this._pageBar.y = 245;
            this.addChild(this._pageBar);
            return;
        }

        public setDefaultPage(arg1: Array<any>): void
        {
            if (arg1) 
            {
                this._pageTool.array = arg1;
            }
            this._pageBar.currentPage = 1;
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this.updateItemListProvider(this._pageTool.getByPageNo(1));
            return;
        }

        public updateItemListProvider(arg1: Array<any>): void
        {
            var loc2=0;
            var loc1=new DataProvider();
            if (!(arg1 == null) && arg1.length > 0) 
            {
                loc2 = 0;
                while (loc2 < arg1.length) 
                {
                    loc1.addItem(arg1[loc2]);
                    ++loc2;
                }
                this._itemListPanel.dataProvider = loc1;
            }
            this._itemListPanel.dataProvider = loc1;
            return;
        }

        /* internal  */onCampComboBoxChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._operCombo.selectedItem.id;
            this.setDefaultPage(Cache.instance.guild.getWarehouseRecodsByType(loc1));
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageBar.currentPage;
            this.updateItemListProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        /* internal */ /* var */_titleTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_operCombo: GComboBox;

        /* internal */ /* var */_itemListPanel: TilePanel;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_operDp: DataProvider;
    }
